package com.wly.dbc
{
	import com.wly.data.ItemPool;
	import com.wly.data.ItemVO;
	import com.wly.data.TypePool;
	import com.wly.data.TypeVO;
	
	import flash.net.URLLoader;

	public class XmlReader
	{
		static public function parserItemXml(xml:XML):void
		{
			var i:int;
			var j:int;
			var typeXml:XML;
			var itemXML:XML;
			var itemVo:ItemVO;
			var type:int;
			
			if(!xml)
			{
				return;
			}
			
			for(i=0; i<xml.child("item").length(); i++)
			{
				itemXML = xml.child("item")[i];
				if(itemXML)
				{
					itemVo = new ItemVO();
					itemVo.url = itemXML.@url;
					itemVo.id  = itemXML.@id;
					itemVo.width = itemXML.@width;
					itemVo.height = itemXML.@height;
					for(j=0; j<itemXML.child("type").length(); j++)
					{
						typeXml = itemXML.child("type")[j];
						type = typeXml.@id;
						itemVo.types.push(type);
					}
					
					ItemPool.getInstance().getItemList().push(itemVo);
				}
			}
		}
		
		static public function parserTypeXml(typesXml:XML):void
		{
			var i:int;
			var type:TypeVO;
			var typeXml:XML;
			var typeItemXml:XML;
			
			if(!typesXml)
			{
				return;
			}
			
			for(i=0; i<typesXml.child("type").length(); i++)
			{
				typeXml = typesXml.child("type")[i];
				
				if(typeXml)
				{
					type = new TypeVO();
					type.id = typeXml.@id;
					type.desc = typeXml.@desc;
					TypePool.getInstance().getTypeList().push(type);
				}
			}
		}
	}
}